package com.andy.web.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.andy.domain.result.BaseResult;
import com.andy.web.user.service.UserService;
import com.andy.web.util.SessionUtil;

@RequestMapping(value="/user")
@RestController
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/login/{username}")
	public BaseResult login(
			@PathVariable(value="username") String username,
			@RequestParam(value="password",required=true) String password) {
		return userService.login(username,password);
	}
	
	@RequestMapping("/reg/{username}")
	public BaseResult reg(
			@PathVariable(value="username") String username, 
			@RequestParam(value="password",required=true) String password,
			@RequestParam(value="email",required=true) String email,
			@RequestParam(value="province",required=true) String province,
			@RequestParam(value="city",required=true) String city) {
		return userService.reg(username,password,email,province,city);
	}
	
	@RequestMapping("/checkActivationCode/{username}/{actCode}")
	public BaseResult checkActivationCode(
			@PathVariable(value="username") String username,
			@PathVariable(value="actCode") String actCode) {
		BaseResult res = new BaseResult();
		boolean success = userService.checkActivationCode(username,actCode);
		res.setValue(success);
		res.setMessage(success?"激活成功":"操作无效");
		return res;
	}
}
